#!/bin/bash
# [[file:example.org::*Get JSON from an API][Get JSON from an API:1]]
URL='https://reqres.in/api/users'
PAGE='1'
curl -s "${URL}?page=${PAGE}" -H "Content-Type: application/json" \
    | jq
# Get JSON from an API:1 ends here

# [[file:example.org::prepare-data][prepare-data]]
USERNAME='morpheus'
JOB='bar'
read -r -d '' DATA <<EOF
{
    "name": "${USERNAME}",
    "job": "${JOB}"
}
EOF
printf "%s" "${DATA}"
# prepare-data ends here

# [[file:example.org::send-request][send-request]]
DATA='{
    "name": "morpheus",
    "job": "bar"
}'
URL='https://reqres.in/api/users'
curl \
    --request POST \
    --silent "${URL}" \
    --header "Content-Type: application/json" \
    --data "${DATA}" \
    | jq -r ".createdAt"
# send-request ends here
